/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.project;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.*;
import queenb.web.controller.QueenbController;
import queenb.web.controller.V050Controller;
import queenb.web.crm.store.V030Store;
import queenb.web.store.B030Store;
import queenb.web.store.C150Store;
import queenb.web.store.C650Store;
import queenb.web.store.EmployeeStore;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.SessionProvider;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class C150Controller extends QueenbController {

    private int FN600;
    private int FV050;
    private String CV151;// Tên công việc 
    private String CB173;// Mô tả
    private int FB050;// Dự án
    private String FC550;// Loại Coongv iệc
    private String FC150;
    private int FC500 = 1;// Trạng thái
    private int FS200; //Chuyên môn
    private Date CD152 = new Date();// Ngày bắt đầu
    private Date CD153 = new Date();// Ngày kết thúc
    private int FS250;// Chuyên môn công việc
    private String CV165;// Tên login khi nhân viên đang nhập 
    private int FC450 = 2;// Độ ưu tiên của dự án
    ComboboxUtil comboboxUtil = new ComboboxUtil();
    private List<SelectItem> combB050 = new ArrayList<SelectItem>();// danh sách dự án
    private List<SelectItem> combS250 = new ArrayList<SelectItem>();// danh sách
    private List<SelectItem> combC550 = new ArrayList<SelectItem>();
    private List<SelectItem> combS200 = new ArrayList<SelectItem>();
    private List<SelectItem> combV050 = new ArrayList<SelectItem>();
    private List<SelectItem> combN100 = new ArrayList<SelectItem>(); // Nhân viên đảm trách
    private List<SelectItem> combN100Pro = new ArrayList<SelectItem>();
    private List<SelectItem> combN850Pro = new ArrayList<SelectItem>();
    private C150Store c150Store;
    private List<C150> listc150;
    private List<V050> listv050;
    private boolean flag;
    private int len;
    private String subString;
    private String CL196;
    private String emp_login;
    private String pageLoad;
    private String pageLoad1;// phan biet dau la them cong viec cua sala hay project
    private String emp;
    private String empId;
    private int PN100;
    private List<SelectItem> listC650R;
    private V030Store v030Store = new V030Store();
    private int fis = 0;
    private String CV166;
    private List<C150> lstC150;
    private int fn850;
    private int startpage = 1;
    private int endpage = 1;
    private int current;
    private int totalpage;
    private int totalrow;
    private int Offset = 0;
    private int Limit = 30;
    private int start; // bat dau lay tu record
    private int end; // lay tu record so
    private int numrow = 30; // so dong tren 1 trang
    private int totalcurent;
    private List<N100> listN100 = new ArrayList<N100>();
    private List<N100> listN100byID = new ArrayList<N100>();
    private int idfn850;
    private String tabGroup = "TABGROUPDA";
    private List<B030> listB030R = new ArrayList<B030>(); 
    public C150Controller() {
        if (SessionProvider.getSessionMapValue("groupID") != null) {
            fn850 = Integer.parseInt(SessionProvider.getSessionMapValue("groupID").toString());
        }
        if (SessionProvider.getSessionMapValue("emp") != null) {
            empId = SessionProvider.getSessionMapValue("emp").toString();
        }
        System.out.println("contructor--fn850--" + fn850 + "--emplogin---" + empId);
        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m17");
        c150Store = new C150Store();
        Object objPage = getRequest().getParameter("page");
        Object objFis = getRequest().getParameter("fis");
        if (objFis != null) {
            fis = Integer.parseInt(objFis.toString());
        }
         Object objFis1111 = getRequest().getParameter("fn600");
        if (objFis1111 != null) {
            FN600 = Integer.parseInt(objFis1111.toString());
            idfn850 = Integer.parseInt(objFis1111.toString());
        }
        
        if (getLogin() != null) {
            PN100 = getLogin().getId();
            CV165 = getLogin().getUserName();
        }
        if (objPage != null) {
            pageLoad = objPage.toString();
        }
        try {
            Object objPagemanager = getRequest().getParameter("manager");
            if (objPagemanager != null) {
                pageLoad1 = objPagemanager.toString();;
            }
//            Object objEmp = getRequest().getParameter("emp");
//            if (objEmp != null) {
//                this.empId = objEmp.toString();
//            } else {
//                empId = getLogin().getUserName();
//            }

            Object pnv050Object = getRequest().getParameter("v050");
            if (pnv050Object != null) {
                this.FV050 = Util.parseInt(pnv050Object);
                System.out.println("==========================FV050" + FV050);
                getListCV050ByID(FV050);
            }
            if (getRequest().getParameter("action") != null) {
                String action = getRequest().getParameter("action").toString();
                System.out.println("action----" + action);
                if (action.equals("edit")) {
                    System.out.println("action---edit 1");
                    Object fn600Object = getRequest().getParameter("FN600");
                    Object pc150Object = getRequest().getParameter("FC150");

                    if (fn600Object != null && objFis != null) {
                        this.FN600 = Util.parseInt(fn600Object);
                        fis = Integer.parseInt(objFis.toString());
//                        this.empId = objEmp.toString();
                        System.out.println("action---edit 2" + FN600 + "," + empId + "," + fis);
                        getC150FByID(FN600, empId, fis);
                    }
                } else if (action.equals("lstCus")) {
                    Object objFv050 = getRequest().getParameter("fv050");
                    if (objFv050 != null) {
                        FV050 = Integer.parseInt(objFv050.toString());
                    }
                    System.out.println("fv050--:" + FV050);
                    Object pc150Object = getRequest().getParameter("FC150");
                    if (pc150Object != null) {
                        this.FC150 = pc150Object.toString();
                        listC650R = getListEmp(FC150);
                    }

                } else if (action.equals("addnew")) {
                    System.out.println("action---add new");
                    CD152 = new Date();
                    CD153 = new Date();
                } else if (action.equals("updatefq100")) {
                    Object objCus = getRequest().getParameter("pn100");
                    Object objE = getRequest().getParameter("fq100");
                    if (objCus != null && objE != null) {
                        int cus = Integer.parseInt(objCus.toString());
                        String e = objE.toString();
                        updateEmpForCus(cus, e);
                    }

                } else if (action.equals("updatevn034")) {

                    Object objCus = getRequest().getParameter("pn100");
                    Object objE = getRequest().getParameter("vn034");
                    System.out.println("D: - updatevn034 -- pn100:" + objCus + "-- vn034 :" + objE);
                    if (objCus != null && objE != null) {
                        int cus = Integer.parseInt(objCus.toString());
                        int e = Integer.parseInt(objE.toString());
                        updateVn034ForCus(cus, e);
                    }

                } else if (action.equals("loadproject")) {
                    objFis = getRequest().getParameter("fis");
                    System.out.println("action---loadproject---" + objFis);
                    if (objFis != null) {
                        fis = Integer.parseInt(objFis.toString());
                    }
                }else if(action.equals("addAllN100Tour")){
                     Object bolcheckall = getRequest().getParameter("boool");
                     if("true".equals(bolcheckall.toString())){
                         List<N100> listcheckall = (List<N100>) SessionProvider.getSessionMapValue("Listn100");
                         if(listcheckall.size()>0){
                             for(int i = 0 ; i <listcheckall.size();i++){
                                 //updateB030();
                             }
                         }
                     }
                }

            }

        } catch (Exception e) {
        }


    }
    public void choosetabADD(){
        setTabGroup("TABADDDA");
        SessionProvider.setSessionMapValue("TABADD", tabGroup);
        idfn850 = fn850;
    }
    public void choosetabGroup(){
        setTabGroup("TABGROUPDA");
        SessionProvider.setSessionMapValue("TABGROUP", tabGroup);
    }
    public void updateC150() throws ParseException {
        String dateStart = ContextUtil.getRequestParameter("dateStart");
        if (dateStart != null && !dateStart.equals("")) {
            CD152 = Util.parseDate(dateStart, "dd/MM/yyyy");
        } else {
            CD152 = null;
        }
        String dateEnd = ContextUtil.getRequestParameter("dateEnd");
        if (dateEnd != null && !dateEnd.equals("")) {
            CD153 = Util.parseDate(dateEnd, "dd/MM/yyyy");
        } else {
            CD153 = null;
        }
        try {
            if (pageLoad.equals("managerSale.jsp") || pageLoad.equals("listTour.jsp")) {
                this.FB050 = FV050;
                if (getCombV050().size() > 0) {
                    for (int a = 0; a < combV050.size(); a++) {
                        if (FB050 == Integer.parseInt(combV050.get(a).getValue().toString())) {
                            CV166 = combV050.get(a).getLabel();
                            break;
                        }
                    }
                }

            } else {//khi tao task o project thi cv166 = null
                this.CV166 = null;
            }
            System.out.println("c150Store.update_C150(" + FC150 + "," + getLogin().getModule() + "," + getLogin().getCompanyNo() + "," + 0 + ","
                    + //int pnFH150, int pnFS200,int pnFC400,int pnFC450,
                    0 + "," + this.FS200 + "," + 0 + "," + this.FC450 + ","
                    + // String pvFC550,int pnFC500, int pnFN600,String pvCV151,
                    this.FC550 + "," + this.FC500 + "," + this.FN600 + "," + this.CV151 + ","
                    + //Date pdCD152,Date pdCD153, String pvCV154,Date pdCD155,
                    Util.toSQLDate(this.CD152) + "," + Util.toSQLDate(CD153) + "," + null + "," + null + ","
                    + //Date pdCD156,String pvCV157,String pvCV158,Date pdCD159,
                    null + "," + null + "," + null + "," + null + ","
                    + // Date pdCD160,String pvCV161,String pvCV162, String pvCV163,
                    null + "," + null + "," + null + "," + null + ","
                    + //String pvCV164, String pvCV165, String pvCV166,int pnCN168,
                    null + "," + this.CV165 + "," + CV166 + "," + this.FB050 + ","
                    + //int pnCN169, int pnCN170, int pnCN171,int pnCN172,
                    this.FS250 + "," + 0 + "," + 0 + "," + 0 + ","
                    + //String plCB173, int pnFC000,String pvLOGIN
                    this.CB173 + "," + 0 + "," + getLogin().getUserName());
            //count = c150Store.update_C150("",getLogin().getModule(), getLogin().getCompanyNo(), 0, 1, 0, 0, this.FC450, null, 0, 0, this.CV151, Util.toSQLDate(this.CD152), Util.toSQLDate(CD153), "CV154", null,null, "CV157",  "CV158", null, null,  "CV161",  "CV162",  "CV163",  "CV164",  this.CV165,  "CV166", this.FB050, this.FS250, 0, 0, 0,this.CB173, 0, getLogin().getUserName());
            //quan ly sale > lay theo du an cua sale

//   int count = 0;
            int count = c150Store.update_C150(
                    //String pvPC150,int pnFH000,int pnFH200L,int pnFH200S,
                    FC150, getLogin().getModule(), getLogin().getCompanyNo(), 0,
                    //int pnFH150, int pnFS200,int pnFC400,int pnFC450,
                    0, this.FS200, 0, this.FC450,
                    // String pvFC550,int pnFC500, int pnFN600,String pvCV151,
                    this.FC550, this.FC500, this.FN600, this.CV151,
                    //Date pdCD152,Date pdCD153, String pvCV154,Date pdCD155,
                    Util.toSQLDate(this.CD152), Util.toSQLDate(CD153), null, null,
                    //Date pdCD156,String pvCV157,String pvCV158,Date pdCD159,
                    null, null, null, null,
                    // Date pdCD160,String pvCV161,String pvCV162, String pvCV163,
                    null, null, null, null,
                    //String pvCV164, String pvCV165, String pvCV166,int pnCN168,
                    null, this.CV165, CV166, this.FB050,
                    //int pnCN169, int pnCN170, int pnCN171,int pnCN172,
                    this.FS250, 0, 0, 0,
                    //String plCB173, int pnFC000,String pvLOGIN
                    this.CB173, 0, getLogin().getUserName());
            if (count >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                if (pageLoad.equals("project.jsp")) {
                    sendRedirectUrlTab("project.jsp?emp=" + empId + "&" + Util.convertMD5(getRequest().getRequestURI()));
                } else {
                    //1: managerSale 2:listTour.jsp
                    sendRedirect(pageLoad);
                }

            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
            }

        } catch (Exception ex) {
            System.out.println("ERROR in C150-------" + ex.getMessage());
            showGlobalReport(true, getResourceString("datasuccessfail"));
            sendRedirect(pageLoad);
        }

    }

    public void getListC150ByID(int pnC150, String emp) {
        try {
            Date date = new Date();
            List<C150> listc150 = c150Store.listC150All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(date), 0, 0, emp, getLogin().getStatus(), 0, 1000, 0, 1, getLogin().getUserName());
            if (listc150 != null && listc150.size() > 0) {
                for (int i = 0; i < listc150.size(); i++) {
                    if (listc150.get(i).getFn600() == FN600) {
                        this.CV151 = listc150.get(i).getCv151();
                        this.FC450 = listc150.get(i).getFc450();
                        this.FC500 = listc150.get(i).getFc500();
                        this.CV165 = listc150.get(i).getLogin();
                        this.CD152 = listc150.get(i).getCd152();
                        this.CD153 = listc150.get(i).getCd153();
                        this.CB173 = listc150.get(i).getCb173();
                        this.FS200 = listc150.get(i).getFs200();
                        this.emp_login = listc150.get(i).getCv165();
                        // this.FS250 = listc150.get(i).getCn169();
                        this.FS250 = listc150.get(i).getFs250();
                        this.FN600 = listc150.get(i).getFn600();
                        System.out.println("++++++++ FN600 +++++++ " + this.FN600 + listc150.get(i).getFn600());
                        this.FB050 = listc150.get(i).getCn168int();
                        System.out.println("++++++++ FB050 +++++++ " + this.FB050 + listc150.get(i).getPb050());
                        this.FC550 = listc150.get(i).getFc550();
                        this.CL196 = listc150.get(i).getCl196();
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    private void getC150FByID(int FN600, String emp, int days) {
        try {
            List<C150> listc150 = null;
            if (days == 0) {
                listc150 = c150Store.listC150All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(new Date()), 0, 0, emp, getLogin().getStatus(), 0, 2, 0, 1, getLogin().getUserName());

            } else if (days == 2) {
                listc150 = c150Store.listC150CR(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(new Date()), 0, 0, emp, getLogin().getStatus(), 0, 2, 0, 1, getLogin().getUserName());

            } else {
                listc150 = c150Store.listC150F(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getStatus(), emp, days, 0, 2, 0, 0, getLogin().getUserName());
            }
            if (listc150 != null && listc150.size() > 0) {
                for (int i = 0; i < listc150.size(); i++) {
                    if (listc150.get(i).getFn600() == FN600) {
                        this.FC150 = listc150.get(i).getPc150();
                        this.CV151 = listc150.get(i).getCv151();
                        this.FC450 = listc150.get(i).getFc450();
                        this.FC500 = listc150.get(i).getFc500();
                        this.CV165 = listc150.get(i).getLogin();
                        this.CD152 = listc150.get(i).getCd152();
                        this.CD153 = listc150.get(i).getCd153();
                        this.CB173 = listc150.get(i).getCb173();
                        this.FS200 = listc150.get(i).getFs200();
                        this.emp_login = listc150.get(i).getCv165();
                        // this.FS250 = listc150.get(i).getCn169();
                        this.FS250 = listc150.get(i).getFs250();
                        this.FN600 = listc150.get(i).getFn600();
                        System.out.println("++++++++ FN600 +++++++ " + this.FN600 + listc150.get(i).getFn600());
                        this.FB050 = listc150.get(i).getCn168int();
                        System.out.println("++++++++ FB050 +++++++ " + this.FB050 + listc150.get(i).getPb050());
                        this.FC550 = listc150.get(i).getFc550();
                        this.CL196 = listc150.get(i).getCl196();
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    private List<C150> listC150F(int days) {
        try {
            System.out.println("getLogin().getStatus()" + getLogin().getStatus() + "----" + days);
            System.out.println("listC150F--emplogin--:" + empId + "--getLogin().getStatus()--" + getLogin().getStatus() + "----" + days);
            List<C150> listc150 = c150Store.listC150F(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getStatus(), empId, days, 0, 30, 0, 0, getLogin().getUserName());

            return listc150;
        } catch (Exception e) {
            return null;
        }

    }

    public List<C150> listAllC150() {
        try {
            Date date = new Date();
            List<C150> lstC150 = null;
//            if (emp == null) {
//                empId = getLogin().getUserName();
//            } else if (emp.equals("0")) {
//                empId = "ALL";
//            }
            if (fis == 2) {
                 System.out.println("--------------CONG VIEC --:"+getLogin().getModule()+","+ getLogin().getCompanyNo()+","+  0+","+  0+","+  null+","+  "P"+","+  Util.toSQLDate(date)+","+  0+","+  0+","+  empId+","+  getLogin().getStatus()+","+  0+","+  1000+","+  0+","+  1+","+  getLogin().getUserName() );
                lstC150 = c150Store.listC150CR(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(date), 0, 0, empId, getLogin().getStatus(), 0, 1000, 0, 1, getLogin().getUserName());

            } else {
                 System.out.println("--------------CONG VIEC --:"+getLogin().getModule()+","+ getLogin().getCompanyNo()+","+  0+","+  0+","+  null+","+  "P"+","+  Util.toSQLDate(date)+","+  0+","+  0+","+  empId+","+  getLogin().getStatus()+","+  0+","+  1000+","+  0+","+  1+","+  getLogin().getUserName() );
                lstC150 = c150Store.listC150All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(date), 0, 0, empId, getLogin().getStatus(), 0, 1000, 0, 1, getLogin().getUserName());
                
            }
           

            return lstC150;

        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        }

    }

    // Lay ham list cua V050
    public List<V050> getListAllV050() {
        try {
            V050Controller v050Controller = new V050Controller();
            List<V050> listV050 = v050Controller.getListAllV050();
            return listV050;
        } catch (Exception e) {
            return null;
        }
    }

    public List<N100> getListCustomer() {
        try {
            System.out.println("---FV050+++++++++++++" + FV050 + "---fn100");
            List<N100> list = v030Store.LISTOFTABV030T(getLogin().getModule(), getLogin().getCompanyNo(), FV050, 0, 0, getLogin().getUserName());
            System.out.println("aaaaaaaaa size" + list.size());
            return list;
        } catch (Exception e) {
            System.out.println("error" + e.getMessage());
            return null;
        }

    }

    public void updateEmpForCus() {
    }

    public void updateEmpForCus(int cus, String emp) {
        try {
            System.out.println("fn100E----:" + cus + "---fn100C--:" + emp);
            int rs = v030Store.updateColumnV030Cus(null, "V030", "FQ100", emp, "FN100", cus, getLogin().getUserName());
            System.out.println("getUpdateEmpForCus rs----:" + rs);


            // String pvSCHEMA, String pvTABNAME, String pvCOLNAME, String pnVALUE, String pvPRIMARYKEY, int pnCONDITION, String pvLOGIN

        } catch (Exception e) {
        }
    }

    public void updateVn034ForCus(int cus, int vn034) {
        try {
            System.out.println("fn100E----:" + cus + "---fn100C--:");
            int rs = v030Store.updateColumnV030VN034(null, "V030", "VN034", vn034, "FN100", cus, getLogin().getUserName());
            System.out.println("getUpdateEmpForCus rs----:" + rs);


            // String pvSCHEMA, String pvTABNAME, String pvCOLNAME, String pnVALUE, String pvPRIMARYKEY, int pnCONDITION, String pvLOGIN

        } catch (Exception e) {
        }
    }

    public List<SelectItem> getListEmp(String fc150) {

        try {
            System.out.println("fc150----:" + fc150);

            return comboboxUtil.getSelectedC650RComb(fc150);

        } catch (Exception e) {
            return null;
        }

    }

    public void getListCV050ByID(int pnV050) {
        try {
            listv050 = getListAllV050();
            if (listv050 != null && listv050.size() > 0) {
                for (int i = 0; i < listv050.size(); i++) {
                    if (listv050.get(i).getFv050() == pnV050) {
                        this.FV050 = listv050.get(i).getFv050();
                        this.CD152 = new Date();
                        this.CD153 = new Date();
                        System.out.println("------------SSSSSS----------" + listv050.get(i).getFv050());
                        System.out.println("----------------------" + FV050);

                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }

    /**
     * @return the CV151
     */
    public String getCV151() {
        return CV151;
    }

    /**
     * @param CV151 the CV151 to set
     */
    public void setCV151(String CV151) {
        this.CV151 = CV151;
    }

    /**
     * @return the CB173
     */
    public String getCB173() {
        return CB173;
    }

    /**
     * @param CB173 the CB173 to set
     */
    public void setCB173(String CB173) {
        this.CB173 = CB173;
    }

    /**
     * @return the FB050
     */
    public int getFB050() {
        return FB050;
    }

    /**
     * @param FB050 the FB050 to set
     */
    public void setFB050(int FB050) {
        this.FB050 = FB050;
    }

    /**
     * @return the CD152
     */
    public Date getCD152() {
        return CD152;
    }

    /**
     * @param CD152 the CD152 to set
     */
    public void setCD152(Date CD152) {
        this.CD152 = CD152;
    }

    /**
     * @return the CD153
     */
    public Date getCD153() {
        return CD153;
    }

    /**
     * @param CD153 the CD153 to set
     */
    public void setCD153(Date CD153) {
        this.CD153 = CD153;
    }

    /**
     * @return the FS250
     */
    public int getFS250() {
        return FS250;
    }

    /**
     * @param FS250 the FS250 to set
     */
    public void setFS250(int FS250) {
        this.FS250 = FS250;
    }

    /**
     * @return the CV165
     */
    public String getCV165() {
        return CV165;
    }

    /**
     * @param CV165 the CV165 to set
     */
    public void setCV165(String CV165) {
        this.CV165 = CV165;
    }

    /**
     * @return the FC450
     */
    public int getFC450() {
        return FC450;
    }

    /**
     * @param FC450 the FC450 to set
     */
    public void setFC450(int FC450) {
        this.FC450 = FC450;
    }

    /**
     * @return the combB050
     */
    public List<SelectItem> getCombB050() {

        combB050 = comboboxUtil.getListCombB050();
        return combB050;
    }

    /**
     * @param combB050 the combB050 to set
     */
    public void setCombB050(List<SelectItem> combB050) {
        this.combB050 = combB050;
    }

    /**
     * @return the combS250
     */
    public List<SelectItem> getCombS250() {
        combS250 = comboboxUtil.getListCombS250();
        return combS250;
    }

    /**
     * @param combS250 the combS250 to set
     */
    public void setCombS250(List<SelectItem> combS250) {
        this.combS250 = combS250;
    }

    /**
     * @return the FC550
     */
    public String getFC550() {
        return FC550;
    }

    /**
     * @param FC550 the FC550 to set
     */
    public void setFC550(String FC550) {
        this.FC550 = FC550;
    }

    /**
     * @return the FC500
     */
    public int getFC500() {
        return FC500;
    }

    /**
     * @param FC500 the FC500 to set
     */
    public void setFC500(int FC500) {
        this.FC500 = FC500;
    }

    /**
     * @return the FS200
     */
    public int getFS200() {
        return FS200;
    }

    /**
     * @param FS200 the FS200 to set
     */
    public void setFS200(int FS200) {
        this.FS200 = FS200;
    }

    /**
     * @return the combC550
     */
    public List<SelectItem> getCombC550() {
        combC550 = comboboxUtil.getListCombC550();

        return combC550;
    }

    /**
     * @param combC550 the combC550 to set
     */
    public void setCombC550(List<SelectItem> combC550) {
        this.combC550 = combC550;
    }

    /**
     * @return the combS200
     */
    public List<SelectItem> getCombS200() {
        combS200 = comboboxUtil.getListCombS200Project();
        return combS200;
    }

    /**
     * @param combS200 the combS200 to set
     */
    public void setCombS200(List<SelectItem> combS200) {
        this.combS200 = combS200;
    }

    /**
     * @return the combN100
     */
    public List<SelectItem> getCombN100() {
        combN100 = comboboxUtil.getListCombN100Project();

        return combN100;
    }

    /**
     * @param combN100 the combN100 to set
     */
    public void setCombN100(List<SelectItem> combN100) {
        this.combN100 = combN100;
    }

    /**
     * @return the FN600
     */
    public int getFN600() {
        return FN600;
    }

    /**
     * @param FN600 the FN600 to set
     */
    public void setFN600(int FN600) {
        this.FN600 = FN600;
    }

    /**
     * @return the flag
     */
    public boolean isFlag() {
        return flag;
    }

    /**
     * @param flag the flag to set
     */
    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    /**
     * @return the FC150
     */
    public String getFC150() {
        return FC150;
    }

    /**
     * @param FC150 the FC150 to set
     */
    public void setFC150(String FC150) {
        this.FC150 = FC150;
    }

    /**
     * @return the len
     */
    public int getLen() {
        return len;
    }

    /**
     * @param len the len to set
     */
    public void setLen(int len) {
        this.len = len;
    }

    /**
     * @return the subString
     */
    public String getSubString() {
        return subString;
    }

    /**
     * @param subString the subString to set
     */
    public void setSubString(String subString) {
        this.subString = subString;
    }

    /**
     * @return the CL196
     */
    public String getCL196() {
        return CL196;
    }

    /**
     * @param CL196 the CL196 to set
     */
    public void setCL196(String CL196) {
        this.CL196 = CL196;
    }

    /**
     * @return the emp_login
     */
    public String getEmp_login() {
        return emp_login;
    }

    /**
     * @param emp_login the emp_login to set
     */
    public void setEmp_login(String emp_login) {
        this.emp_login = emp_login;
    }

    /**
     * @return the pageLoad
     */
    public String getPageLoad() {
        return pageLoad;
    }

    /**
     * @param pageLoad the pageLoad to set
     */
    public void setPageLoad(String pageLoad) {
        this.pageLoad = pageLoad;
    }

    /**
     * @return the pageLoad1
     */
    public String getPageLoad1() {
        return pageLoad1;
    }

    /**
     * @param pageLoad1 the pageLoad1 to set
     */
    public void setPageLoad1(String pageLoad1) {
        this.pageLoad1 = pageLoad1;
    }

    /**
     * @return the combV050
     */
    public List<SelectItem> getCombV050() {
        combV050 = comboboxUtil.getListCombV050Sale();
        return combV050;
    }

    /**
     * @param combV050 the combV050 to set
     */
    public void setCombV050(List<SelectItem> combV050) {
        this.combV050 = combV050;
    }

    /**
     * @return the FV050
     */
    public int getFV050() {
        return FV050;
    }

    /**
     * @param FV050 the FV050 to set
     */
    public void setFV050(int FV050) {
        this.FV050 = FV050;
    }

    /**
     * @return the emp
     */
    public String getEmp() {

        return emp;
    }

    /**
     * @param emp the emp to set
     */
    public void setEmp(String emp) {
        this.emp = emp;
    }

    /**
     * @return the empId
     */
    public String getEmpId() {
        if (getLogin() != null) {
            if (empId == null) {
                empId = getLogin().getUserName();
            }
        }
        return empId;
    }

    /**
     * @param empId the empId to set
     */
    public void setEmpId(String empId) {
        this.empId = empId;
    }

    /**
     * @return the combN100Pro
     */
    public List<SelectItem> getCombN100Pro() {
        String emp = empId;
        try {
            combN100Pro = comboboxUtil.getSelectedN900Comb(getFn850());
            for (int i = 0; i < combN100Pro.size(); i++) {
                if (combN100Pro.get(i).getValue().toString().equals(empId)) {
                    //neu nhan vien dc chon co trong nhom to
                    emp = combN100Pro.get(i).getValue().toString();
                    break;
                } else {//neu ko co thi gan la ng dau tien
                    emp = combN100Pro.get(0).getValue().toString();
                }
            }
            empId = emp;
            SessionProvider.setSessionMapValue("emp", empId);

        } catch (Exception e) {
            System.out.println("getLstEmpByID error--:" + e.getMessage());
            combN100Pro = new ArrayList<SelectItem>();
        }

        System.out.println("getLstEmpByID-size-" + combN100Pro.size() + "---fn850--" + fn850 + "--emplogin--" + empId);
        return combN100Pro;
//        try {
//            if (getLogin() != null) {
//                combN100Pro = comboboxUtil.getListCombN100Pro();
//                for (int i = 0; i < combN100Pro.size(); i++) {
//                    SelectItem item = combN100Pro.get(i);
//                    if (item.getValue() != null) {
//                        if (item.getValue().toString().equals(empId)) {
//                            emp = item.getLabel();
//                            System.out.println("empid---" + empId);
//                            break;
//                        }
//                    }
//                }
//            } else {
//                sendRedirect("login.jsp");
//            }
//            return combN100Pro;
//        } catch (Exception ex) {
//            return null;
//        }
    }

    public void actionComb(ValueChangeEvent evt) {
        System.out.println("---value===" + evt.getNewValue());
    }

    /**
     * @param combN100Pro the combN100Pro to set
     */
    public void setCombN100Pro(List<SelectItem> combN100Pro) {
        this.combN100Pro = combN100Pro;
    }

    /**
     * @return the PN100
     */
    public int getPN100() {
        return PN100;
    }

    /**
     * @param PN100 the PN100 to set
     */
    public void setPN100(int PN100) {
        this.PN100 = PN100;
    }

    /**
     * @return the listC650R
     */
    public List<SelectItem> getListC650R() {
//        if(listC650R ==null && listC650R.isEmpty()){
//            System.out.println("getListC650R null");
//            listC650R = getListEmp(FC150);
//        }
        return listC650R;
    }

    /**
     * @param listC650R the listC650R to set
     */
    public void setListC650R(List<SelectItem> listC650R) {
        this.listC650R = listC650R;
    }

    /**
     * @return the fis
     */
    public int getFis() {
        return fis;
    }

    /**
     * @param fis the fis to set
     */
    public void setFis(int fis) {
        this.fis = fis;
    }

    /**
     * @return the lstC150
     */
    public List<C150> getLstC150() {
        try {
            if (fis == 0 || fis == 2) {
                lstC150 = listAllC150();
            } else {
                lstC150 = listC150F(fis);
            }     
            if (Offset == 0) {
                if (lstC150.size() > 0) {
                    C150 n100 = lstC150.get(0);
                    if (n100 != null) {
                        SessionProvider.setSessionMapValue("totalcurentE", n100.getRow());
                        //totalcurent = n100.getRowss();
                    } else {
                        SessionProvider.setSessionMapValue("totalcurentE", 0);
                        //totalcurent = 0;
                    }
                } else {
                    SessionProvider.setSessionMapValue("totalcurentE", 0);
                    //totalcurent = 0;
                }
            }
            //paging
            int t;
            Object obj = SessionProvider.getSessionMapValue("totalcurentE");
            if (obj != null) {
                try {
                    t = Integer.parseInt(obj.toString());
                } catch (Exception e) {
                    t = 0;
                }
                setTotalcurent(t);
            } else {
                setTotalcurent(0);
            }

            setTotalrow(getTotalcurent());
            return lstC150;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @param lstC150 the lstC150 to set
     */
    public void setLstC150(List<C150> lstC150) {
        this.lstC150 = lstC150;
    }

    /**
     * @return the CV166
     */
    public String getCV166() {
        return CV166;
    }

    /**
     * @param CV166 the CV166 to set
     */
    public void setCV166(String CV166) {
        this.CV166 = CV166;
    }

    /**
     * @return the fn850
     */
    public int getFn850() {
        return fn850;
    }

    /**
     * @param fn850 the fn850 to set
     */
    public void setFn850(int fn850) {
        this.fn850 = fn850;
    }

    /**
     * @return the startpage
     */
    public int getStartpage() {
        if (startpage < 1) {
            startpage = 1;
        }
        return startpage;
    }

    /**
     * @param startpage the startpage to set
     */
    public void setStartpage(int startpage) {
        this.startpage = startpage;
    }

    /**
     * @return the endpage
     */
    public int getEndpage() {
        if (endpage > totalpage) {
            endpage = totalpage;
        }
        return endpage;
    }

    /**
     * @param endpage the endpage to set
     */
    public void setEndpage(int endpage) {
        this.endpage = endpage;
    }

    /**
     * @return the current
     */
    public int getCurrent() {
        if (current > totalpage) {
            current = totalpage;
        } else if (current < 1) {
            current = 1;
        }
        return current;
    }

    /**
     * @param current the current to set
     */
    public void setCurrent(int current) {
        setStart((current - 1) * getNumrow());
        setEnd(current * getNumrow());
        this.current = current;
    }

    /**
     * @return the totalpage
     */
    public int getTotalpage() {
        return totalpage;
    }

    /**
     * @param totalpage the totalpage to set
     */
    public void setTotalpage(int totalpage) {
        this.totalpage = totalpage;
    }

    /**
     * @return the totalrow
     */
    public int getTotalrow() {
        return totalrow;
    }

    /**
     * @param totalrow the totalrow to set
     */
    public void setTotalrow(int totalrow) {
        totalpage = totalrow / getNumrow();

        if (totalrow % getNumrow() > 0) {
            totalpage = totalpage + 1;
        }


        if (getTotalpage() <= 10) {
            setStartpage(1);
            setEndpage(getTotalpage());

        } else {
            setStartpage(current - 5);
            setEndpage(current + 5);


        }
        this.totalrow = totalrow;
    }

    /**
     * @return the start
     */
    public int getStart() {
        if (start == 0) {
            start = 1;
        }
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(int start) {
        this.start = start;
    }

    /**
     * @return the end
     */
    public int getEnd() {
        if (end == 0) {
            end = 20;
        }
        return end;
    }

    /**
     * @param end the end to set
     */
    public void setEnd(int end) {
        this.end = end;
    }

    /**
     * @return the numrow
     */
    public int getNumrow() {
        if (numrow == 0) {
            numrow = 30;
        }
        return numrow;
    }

    /**
     * @param aNumrow the numrow to set
     */
    public void setNumrow(int aNumrow) {
        numrow = aNumrow;
    }

    /**
     * @return the totalcurent
     */
    public int getTotalcurent() {
        return totalcurent;
    }

    /**
     * @param totalcurent the totalcurent to set
     */
    public void setTotalcurent(int totalcurent) {
        this.totalcurent = totalcurent;
    }

    /**
     * @return the combN850Pro
     */
    public List<SelectItem> getCombN850Pro() {
        try {
            combN850Pro = comboboxUtil.getSelectedN850Comb();
           
            return combN850Pro;
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * @param combN850Pro the combN850Pro to set
     */
    public void setCombN850Pro(List<SelectItem> combN850Pro) {
        this.combN850Pro = combN850Pro;
    }
    public void actionSearchfn850() {
        try {  
            System.out.println("----------ABABABABAB------------- : " + FN600);
            SessionProvider.setSessionMapValue("IDfn850onchange", FN600);
        } catch (Exception e) {
        }


    }
    /**
     * @return the listN100
     */
    public List<N100> getListN100() {
      EmployeeStore employeeStore = new EmployeeStore();
      if(SessionProvider.getSessionMapValue("IDfn850onchange") != null){
        System.out.println("Call IDfn850onchange ---- : "+SessionProvider.getSessionMapValue("IDfn850onchange").toString());   
        idfn850 = Util.parseInt(SessionProvider.getSessionMapValue("IDfn850onchange"));
      }
      listN100 =  employeeStore.getAllListTabN100All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, idfn850, 0, null, 0, 1000, 0, 0, getLogin().getUserName());
      System.out.println("Call list N100 by fn850 ---- : "+idfn850+"---------"+listN100.size());       
      if(listN100.size() >0){
          SessionProvider.setSessionMapValue("Listn100",listN100);
      }
      return listN100;
    }

    /**
     * @param listN100 the listN100 to set
     */
    public void setListN100(List<N100> listN100) {
        this.listN100 = listN100;
    }

    /**
     * @return the idfn850
     */
    public int getIdfn850() {
        if(SessionProvider.getSessionMapValue("IDfn850onchange") != null){
           idfn850 = Util.parseInt(SessionProvider.getSessionMapValue("IDfn850onchange"));
        }
        return idfn850;
    }

    /**
     * @param idfn850 the idfn850 to set
     */
    public void setIdfn850(int idfn850) {
        this.idfn850 = idfn850;
    }

    /**
     * @return the tabGroup
     */
    public String getTabGroup() {
        return tabGroup;
    }

    /**
     * @param tabGroup the tabGroup to set
     */
    public void setTabGroup(String tabGroup) {
        this.tabGroup = tabGroup;
    }

    /**
     * @return the listN100byID
     */
    public List<N100> getListN100byID() {
        
        return listN100byID;
    }

    /**
     * @param listN100byID the listN100byID to set
     */
    public void setListN100byID(List<N100> listN100byID) {
        this.listN100byID = listN100byID;
    }

    /**
     * @return the listB030R
     */
    public List<B030> getListB030R(){
        try {
            B030Store b030Store = new B030Store();
            System.out.println("--------CAL LIST NV THUOC DU AN------------: "+getLogin().getModule() + "," + getLogin().getCompanyNo()+ "," + FB050+ "," + 0+ "," + getLogin().getUserName());
            listB030R = b030Store.getListB030R(getLogin().getModule(), getLogin().getCompanyNo(), FB050, 0, getLogin().getUserName());
        } catch (Exception e) {
            listB030R = null;
        }
        return listB030R;
    }

    /**
     * @param listB030R the listB030R to set
     */
    public void setListB030R(List<B030> listB030R) {
        this.listB030R = listB030R;
    }
    
    
    
}
